package com.bosssoft.cloud.wechat.common.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.bosssoft.cloud.app.domain.AppCheckCount;
import com.bosssoft.cloud.wechat.common.bean.einvoice.EinvoiceDTO;
import com.bosssoft.cloud.wechat.common.service.AppCheckCountService;
import com.bosssoft.cloud.wechat.infrastructure.util.ETimeUtil;
import com.bosssoft.cloud.wechat.infrastructure.util.IDUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;


/**
 * @author wcy create on 2021/5/14 16:09 下午
 */
@Slf4j
@Service
public class AppCheckCountServiceImpl implements AppCheckCountService {//extends ServiceImpl<AppcheckcountMapper, Appcheckcount> implements AppcheckcountService {

    @Autowired
    private com.bosssoft.cloud.app.service.AppCheckCountService accService;

    @Async
    @Override
    public void save(EinvoiceDTO dto) {
        /*
        记录用户查验记录
         */
        AppCheckCount count = BeanUtil.toBean(dto, AppCheckCount.class);
        // 设置id和查验时间
        setCheckTimes(count);
        count.setId(IDUtil.randomUUID());
        accService.insert(count);
    }

    @Override
    public void setCheckTimes(AppCheckCount checkCount) {
        String[] timestr = ETimeUtil.getDateTime();
        checkCount.setCheckDate(timestr[0]);
        checkCount.setCheckTime(timestr[1]);
    }

}
